package com.marvin.springBoot.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author marvin.ma
 * @create 2017-09-28 23:37
 * @desc swagger配置
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    /**
     * swagger摘要bean
     * @return
     */
    @Bean
    public Docket restApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.marvin.springBoot.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    /**
     * API文档主信息对象
     * @return
     */
    private ApiInfo apiInfo(){
        ApiInfo apiInfo= (new ApiInfoBuilder())
                .title("Good相关接口文档V1")
                .description("api文档")
                //                .termsOfServiceUrl("NO terms of service")
                .contact("marvin:mmdebug@126.com")
                .version("1.0")
                .build();
        return apiInfo;
    }
}
